﻿namespace AnyOffice.DAL
{
    using AnyOffice.Model;
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class AssetDpctSubDao
    {
        public int Insert(SqlConnection conn, AssetDpctSubData data)
        {
            string commandText = "INSERT INTO [dbo].[Asset_DpctSub] ( [CptlId], [PepreDate], [FromYYMM], [ToYYMM], [DepreAmt] ) VALUES ( @CptlId, @PepreDate, @FromYYMM, @ToYYMM, @DepreAmt ) SELECT SCOPE_IDENTITY() AS RetValue";
            SqlParameter[] commandParameters = new SqlParameter[5];
            commandParameters[0] = new SqlParameter("@CptlId", SqlDbType.Int);
            commandParameters[0].Value = data.CptlId;
            commandParameters[1] = new SqlParameter("@PepreDate", SqlDbType.DateTime);
            commandParameters[1].Value = data.PepreDate;
            commandParameters[2] = new SqlParameter("@FromYYMM", SqlDbType.VarChar);
            commandParameters[2].Value = data.FromYYMM;
            commandParameters[3] = new SqlParameter("@ToYYMM", SqlDbType.NVarChar, 10);
            commandParameters[3].Value = data.ToYYMM;
            commandParameters[4] = new SqlParameter("@DepreAmt", SqlDbType.Decimal);
            commandParameters[4].Precision = 0x12;
            commandParameters[4].Scale = 2;
            commandParameters[4].Value = data.DepreAmt;
            object obj2 = SqlHelper.ExecuteScalar(conn, CommandType.Text, commandText, commandParameters);
            if (obj2 != DBNull.Value)
            {
                return Convert.ToInt32(obj2);
            }
            return -1;
        }

        public DataTable SelectByCptlId(SqlConnection conn, int cptlId)
        {
            string commandText = "SELECT * FROM [dbo].[Asset_DpctSub] WHERE [CptlId] = @CptlId";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@CptlId", SqlDbType.Int) };
            commandParameters[0].Value = cptlId;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Asset_DpctSub";
            return set.Tables[0];
        }
    }
}

